<div id="page-heading"><h1><?php echo lang('articles.manage_title'); ?></h1></div>
<?php $this->load->view('partials/notices'); ?>
<?php 
	$categories_options = array();
	foreach($categories as $_category){
		$categories_options[$_category->id] = empty($_category->name)? lang('global:empty'): $_category->name;
	}
?>
<form method="post" action="<?php echo site_url('admin/catalog/search_articles');?>">	
<table cellspacing="0" cellpadding="0" border="0" id="id-form">
		<tbody><tr>
			<td><?php echo form_input('keyword', $keyword, 'class="inp-form" name="keyword" id="keyword"'); ?></td>
			<td><?php echo lang('activate_label'); ?>:</td>
			<td><?php echo form_dropdown('active', array('all' => lang('global:select-all'), 1 => lang('global:yes'), 0 => lang('global:no') ), array($active), 'class="select_box" style="width:150px;"'); ?></td>
			<td><?php echo lang('articles.category_id'); ?>:</td>
			<td><?php echo form_dropdown('category', array(0 => lang('global:select-all')) + $categories_options, array($category) , 'class="select_box" style="width:150px;"'); ?></td>
			<td valign="top">
			<input type="submit" class="form-submit" value="">
		</td>
		</tr>
	</tbody></table>
	</form>
<?php if ($articles): ?>	
<?php echo form_open('admin/catalog/action_article', 'id="mainform"');?>
<table cellspacing="0" cellpadding="0" border="0" width="100%" id="product-table">
				<tbody>
				<tr>
				<?php if (group_has_role('catalog', 'delete_article')): ?>
					<th class="table-header-check"><a id="toggle-all" ></a> </th>
				<?php endif;?>
					<th class="table-header-repeat line-left"><a href="javascript:void(0);"><?php echo lang('articles.name_label'); ?></a></th>
					<th class="table-header-repeat line-left"><a href="javascript:void(0);"><?php echo lang('articles.category_id'); ?></a></th>
					<th class="table-header-repeat line-left"><a href="javascript:void(0);"><?php echo lang('global:created'); ?></a></th>
					<th class="table-header-repeat line-left"><a href="javascript:void(0);"><?php echo lang('global:status'); ?></a></th>
					<th class="table-header-repeat line-left"><a href="javascript:void(0);"><?php echo lang('global:actions')?></a></th>
				</tr>
				<?php foreach ($articles as $key => $article): ?>
				<tr <?php if($key%2 == 0):?>class="alternate-row"<?php endif;?>>
					<?php if (group_has_role('catalog', 'delete_article')): ?>
						<td><?php echo form_checkbox('action_to[]', $article->id); ?></td>
					<?php endif; ?>
					<td><?php echo anchor('admin/catalog/edit_article/' . $article->id, $article->name, 'title="' . $article->name .'" class="folder-hash"'); ?></td>
					<td>
					<?php 
					foreach($categories as $category){
						if($article->category_id == $category->id){
							echo $category->name;
							break;
						}
					}
					?>
					</td>
					<td><?php echo date('Y-m-d', $article->created)?></td>
					<td><?php if($article->status):?><?php echo lang('global:yes')?><?php else:?><?php echo lang('global:no')?><?php endif;?></td>
					<td class="options-width">
					<?php if (group_has_role('catalog', 'edit_article')): ?>
						<?php echo anchor('admin/catalog/edit_article/' . $article->id, ' ', 'title="'. lang('buttons.edit').'" class="icon-1 info-tooltip"'); ?>
						<?php endif; ?>
						<?php if (group_has_role('catalog', 'delete_article')): ?>
						<a class="icon-2 info-tooltip" title="<?php echo lang('buttons.delete');?>" href="javascript:void(0);" onclick="if(confirm('<?php echo lang('global:delete')?>')){window.location.href='<?php echo site_url('admin/catalog/delete_article/' . $article->id);?>'}"></a>
						<?php endif; ?>
					</td>
				</tr>
				<?php endforeach;?>
				</tbody>
</table>
<input type="hidden" name="btnAction"  id="btnAction" value=""/>
<?php if (group_has_role('catalog', 'delete_article') || group_has_role('catalog', 'activate_article') || group_has_role('catalog', 'deactivate_article')): ?>
<script type="text/javascript">
	function submit_form(type)
	{
		if('activate' == type){
			$('#btnAction').val('activate');
		}else if('deactivate' == type){
			$('#btnAction').val('deactivate');
		}else if('delete' == type){
			$('#btnAction').val('delete');
		}
		$('#mainform').submit();
	}
</script>
<div id="actions-box">
	<a href="" class="action-slider"></a>
	<div id="actions-box-slider">
		<?php if (group_has_role('catalog', 'delete_article')): ?>
		<a href="javascript:void(0);" onclick="submit_form('delete');" class="action-delete">Delete</a>
		<?php endif;?>
		<?php if (group_has_role('catalog', 'activate_article')): ?>
			<a href="javascript:void(0);" onclick="submit_form('activate');" class="action-edit"><?php echo lang('activate_label');?></a>
		<?php endif;?>
		<?php if (group_has_role('catalog', 'deactivate_article')): ?>
			<a href="javascript:void(0);" onclick="submit_form('deactivate');" class="action-edit"><?php echo lang('deactivate_label');?></a>
		<?php endif;?>
	</div>
	<div class="clear"></div>
</div>
<?php endif; ?>
<div align=center><div class="inner"><?php $this->load->view('partials/pagination'); ?></div></div>
<?php echo form_close();?>

<?php else: ?>
	<div class="no_data file-articles">
		<p><?php echo lang('articles.no_article');?></p>
		<br />
		<p>[<a href="<?php echo site_url('admin/catalog/create_article')?>"><?php echo lang('menu_2_catalog_create_article')?></a>]</p>
	</div>
<?php endif; ?>